package com.zhang.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhang.domain.ArticleComment;
import com.zhang.domain.SubjectArticle;
import com.zhang.entity.vo.ArticleCommentVo;
import java.util.List;
import java.util.Map;
import java.util.Set;
import xin.altitude.cms.common.util.BeanCopyUtils;
import xin.altitude.cms.common.util.EntityUtils;
import xin.altitude.cms.common.util.SpringUtils;

public interface IArticleCommentService extends IService<ArticleComment>{
    ISubjectArticleService subjectArticleService = SpringUtils.getBean(ISubjectArticleService.class);
    /**查询用户实体类Vo*/    default ArticleCommentVo getOneVo(Long id) {
        ArticleCommentVo articleCommentVo = EntityUtils.toObj(getById(id), ArticleCommentVo::new);
        SubjectArticle subjectArticle = subjectArticleService.getById(articleCommentVo.getId());
        BeanCopyUtils.copyProperties(subjectArticle, articleCommentVo);
        return articleCommentVo;
    }
    /**查询实体类Vo列表*/    default List<ArticleCommentVo> listVo(ArticleComment articleComment) {
        List<ArticleCommentVo> articleCommentVoList = EntityUtils.toList(list(Wrappers.lambdaQuery(articleComment)), ArticleCommentVo::new);
        Set<Long> subjectArticleIds = EntityUtils.toSet(articleCommentVoList, ArticleCommentVo::getArticleId);
        Map<Long, SubjectArticle> map = EntityUtils.toMap(subjectArticleService.listByIds(subjectArticleIds), SubjectArticle::getId, e -> e);
        articleCommentVoList.forEach(e -> BeanCopyUtils.copyProperties(map.get(e.getArticleId()), e));
        return articleCommentVoList;
    }
    /**分页查询实体类Vo*/    default IPage<ArticleCommentVo> pageVo(IPage<ArticleComment> page, ArticleComment articleComment) {
        IPage<ArticleCommentVo> articleCommentVoPage = EntityUtils.toPage(page(page, Wrappers.lambdaQuery(articleComment)), ArticleCommentVo::new);
        Set<Long> subjectArticleIds = EntityUtils.toSet(articleCommentVoPage.getRecords(), ArticleCommentVo::getArticleId);
        Map<Long, SubjectArticle> map = EntityUtils.toMap(subjectArticleService.listByIds(subjectArticleIds), SubjectArticle::getId, e -> e);
        articleCommentVoPage.getRecords().forEach(e -> BeanCopyUtils.copyProperties(map.get(e.getArticleId()), e));
        return articleCommentVoPage;
    }
}
